<template>
  <view class="container">
    <view class="header">
      <view class="integral">
        <span class="integral-amount">{{ userInfo.gpWyPaymentAmount || 0 }}</span
        >补贴
      </view>
      <view class="all-houses" @click="onLink">
        全部房源
        <u-icon name="arrow-right" size="30"></u-icon>
      </view>
    </view>
    <view class="bill-list">
      <view class="bill-title">个人账单</view>
      <view v-for="(item, index) in listData" :key="index" class="bill-item">
        <!-- <view class="bill-icon">
          <image class="icon-image" :src="getImg(item.image)"></image>
        </view> -->
        <view class="bill-details">
          <view class="bill-title-details">{{ item.title }}</view>
          <view class="bill-price">
            {{ item.title ? item.title : item.mark }}
            <text class="price-value" :class="{ positive: item.pm !== 0 }">
              {{ item.pm === 0 ? "-￥" : "+" }}{{ item.payPrice == "" || item.payPrice == null ? item.mark : item.payPrice }}
            </text>
          </view>
          <view class="bill-refund">
            <span>返还补贴</span>
            <text class="refund-value"> {{ item.gainIntegralProperty }} </text>
          </view>
          <view v-if="item.ebComunityHouseName" class="bill-community">{{ item.ebComunityHouseName }}</view>
          <view class="bill-consumption-time">
            <span>消费时间：</span>
            {{ item.add_time }}
          </view>
        </view>
      </view>
      <view v-if="loading" class="loading">我是有底线的</view>
    </view>
    <view class="footer">
      <button class="deduct-button" type="info" @click="onLink" :loading="loadBtn">去抵扣物业费</button>
    </view>
  </view>
</template>

<script>
import { propertyProvidentHomepage } from "../../../utils/api/wy.js";
import { IMG_URL } from "../../../config/index";
export default {
  data() {
    return {
      loading: false,
      loadBtn: false,
      goodScroll: true,
      imgurl: IMG_URL,
      params: {
        page: 1,
        limit: 10,
      },
      listData: [],
      userInfo: "",
    };
  },
  onShow() {
    this.userInfo = uni.getStorageSync("userInfo");
  },
  onLoad() {
    this.fetchData();
  },
  onReachBottom() {
    this.fetchData();
  },
  methods: {
    onLink() {
      uni.navigateTo({
        url: `/pages_h5/wy/index_list/house_info?type=1`,
      });
    },
    fetchData() {
      this.loading = true;
      if (!this.goodScroll) return;
      propertyProvidentHomepage({
        ...this.params,
        userId: uni.getStorageSync("uid"),
      }).then((res) => {
        this.loading = false;
        this.goodScroll = (res.data.userBillList || []).length >= this.params.limit;
        this.params.page++;
        this.listData = this.listData.concat(res.data.userBillList || []);
      });
    },
    getImg(imageUrl) {
      return imageUrl || "default-image-url"; // 如果imageUrl不存在，返回默认图片地址
    },
  },
};
</script>

<style lang="less" scoped>
.container {
  background-color: #f6f6f6;
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 10px;
  background-color: #ffffff;
  margin-bottom: 20rpx;
  height: 50px;
  line-height: 50px;
}

.integral {
  font-size: 24rpx;
  font-weight: bold;
}

.integral-amount {
  margin-right: 10rpx;
  font-size: 40rpx;
  font-weight: bold;
  color: #ff8c00;
}

.all-houses {
  font-size: 28rpx;
  color: #000;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.arrow {
  margin-left: 10rpx;
}

.bill-list {
  flex: 1;
  padding: 20rpx;
  padding-bottom: 140rpx; // 为底部按钮腾空间
}

.bill-title {
  font-size: 30rpx;
  font-weight: bold;
  margin-bottom: 20rpx;
  background-color: #f5f5f5;
}

.bill-item {
  display: flex;
  padding: 20rpx;
  margin-bottom: 20rpx;
  background-color: #fff;
  border-radius: 10rpx;
}

.bill-icon {
  margin-right: 20rpx;
}

.icon-image {
  width: 100rpx;
  height: 100rpx;
  border-radius: 10rpx;
}

.bill-details {
  flex: 1;
}

.bill-title-details {
  font-size: 30rpx;
  color: #000;
}

.bill-price {
  display: flex;
  align-items: center;
  margin: 10rpx 0;
  font-size: 12px;
  color: #666;
}

.price-value {
  font-size: 26rpx;
  font-weight: bold;
  margin-left: 10px;
}

.positive {
  color: green;
}

.bill-refund {
  display: flex;
  align-items: center;
  margin-bottom: 10rpx;
  font-size: 12px;
  color: #666;
}

.refund-value {
  font-size: 28rpx;
  font-weight: bold;
  margin-left: 10rpx;
  color: #ff5e0b;
}

.bill-community,
.bill-link-id,
.bill-consumption-time {
  font-size: 12px;
  color: #666;
}

.footer {
  position: fixed;
  bottom: 0;
  width: 100%;
  padding: 40rpx 0;
  padding-bottom: 40rpx;
  background-color: #f5f5f5;
  box-shadow: 0 -10rpx 10rpx rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
}

.deduct-button {
  width: calc(100% - 20rpx) !important;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 90rpx;
  background: linear-gradient(90deg, #ff5e0b 0%, #ff7c02 100%);
  border-radius: 50rpx;
  font-weight: 600;
  font-size: 32rpx;
  color: #ffffff;
}

.loading {
  text-align: center;
  padding: 10rpx;
  color: #888;
}
</style>
